package org.tbjd.client.widgetProviders;

import org.tbjd.client.beans.Task;
import org.tbjd.client.customWidgets.BeginDateTextBox;
import org.tbjd.client.customWidgets.CollapseButton;
import org.tbjd.client.customWidgets.DurationTextBox;
import org.tbjd.client.customWidgets.EndDateTextBox;
import org.tbjd.client.customWidgets.ProgressTextBox;
import org.tbjd.client.customWidgets.taskList.TreeGridItemHandle;
import org.tbjd.client.images.taskList.TaskListImageBundle;
import org.tbjd.client.interfaces.WidgetProvider;

import com.google.gwt.core.client.GWT;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Widget;

public class TasksListWidgetProvider implements WidgetProvider {

	private TaskListImageBundle taskImageBundle = (TaskListImageBundle) GWT.create(TaskListImageBundle.class);

	public Widget getWidget(Object o, int columnIndex) {

		Task task = (Task) o;

		TreeGridItemHandle handle = new TreeGridItemHandle();
		CollapseButton pbCollapse = null;

		switch (columnIndex) {

		case 0:
			if (task.getType() == Task.PHASE) {
				pbCollapse = new CollapseButton(task, taskImageBundle.plus13x13().createImage(), taskImageBundle.minus13x13().createImage());
				pbCollapse.setStyleName("outlineNone");

				return pbCollapse;
			}

			return new HTML("");

		case 1:
			handle = new TreeGridItemHandle(task.getName());
			handle.setTask(task);
			return handle;

		case 2:
			DurationTextBox durationTextBox = new DurationTextBox(task);
			durationTextBox.setText(String.valueOf(task.getDuration()));
			durationTextBox.setStyleName("customTextBox");
			durationTextBox.setWidth("50px");

			return durationTextBox;

		case 3:
			ProgressTextBox progressTextBox = new ProgressTextBox(task);
			progressTextBox.setText(String.valueOf(task.getProgress()));
			progressTextBox.setStyleName("customTextBox");
			progressTextBox.setWidth("50px");

			return progressTextBox;
		
		case 4:
			BeginDateTextBox beginDateTextBox = new BeginDateTextBox(task);
			beginDateTextBox.setText(String.valueOf(DateTimeFormat.getShortDateFormat().format(task.getBeginDate())));
			beginDateTextBox.setStyleName("customTextBox");
			beginDateTextBox.setWidth("75px");

			return beginDateTextBox;
			
		case 5:
			EndDateTextBox endDateTextBox = new EndDateTextBox(task);
			endDateTextBox.setText(String.valueOf(DateTimeFormat.getShortDateFormat().format(task.getEndDate())));
			endDateTextBox.setStyleName("customTextBox");
			endDateTextBox.setWidth("75px");

			return endDateTextBox;

		default:

			break;
		}

		return null;
	}

	public Widget getWidget(Object o) {
		return null;
	}

}